package com.example.allshengmedical.experimentanalyze.activity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.allsheng.matrix.LeastSquareMethod;
import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.base.BaseFragment;
import com.example.allshengmedical.experimentnew.bean.LayoutTableBean;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.MathLog;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineDataSet;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

//rawdata的第二个界面
public class TableFragment extends BaseFragment {

	public interface MyListener {
		public void showMessage(int position, int type);
	}

	private MyListener mListener;
	ListView table_list;
	TextView show_tv;
	TableAdapter tableAdapter;
	CheckBox well_check, Omit_check, Sample_check, TargetName_check, Task_check, Dyes_check, Ct_check, Ct_Mean_check,
			Ct_SD_check, Quantity_check, SE_check, Slop_check, RQ_check, RQ_Min_check, RQ_Max_check, MIGHSD_check,
			comments_check;

	ArrayList<TableFraBean> tableFraBeans = new ArrayList<TableFraBean>();
	ArrayList<TableFraBean> tableFraBeansShow = new ArrayList<TableFraBean>();

	// 数据
	String folderName;
	String fileName;
	private String appFilePath = Environment.getExternalStorageDirectory() + "/" + "AllShengMedical";
	StringBuffer contextString = new StringBuffer();
	// 基因盘数据
	public ArrayList<LayoutTableBean> activityLayoutTableBeans;
	// 基因盘数据
	public List<HashMap<String, Object>> dataSourceListBlock1 = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlock2 = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlock1Old = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlock2Old = new ArrayList<HashMap<String, Object>>();

	// 曲线图
	// 上半部
	private ArrayList<MethodBean> activityMethodBeans = new ArrayList<MethodBean>();
	// 重复次数
	private int repititions;

	// ct数据
	public HashMap<Integer, LineDataSet> dataListCTArrayList = new HashMap<Integer, LineDataSet>();
	private String experimentType;
	private String endogenousControl;
	private String referenceSample;

	LeastSquareMethod myLeastSquareMethod = new LeastSquareMethod();
	public ArrayList<StandCurveBean> standCurveBeans = new ArrayList<StandCurveBean>();
	private ArrayList<Double> linshiList;
	private ArrayList<String> smpleYValeueArrayList;
	private HashMap<String, HashSet<String>> hashMap2;

	private TextView quantityTv, norquantityTv, norsequantityTv;
	
	RelativeLayout white_line;

	@Override
	public void onAttach(Activity activity) {/* 判断宿主activity是否实现了接口MyListener */
		super.onAttach(activity);
		try {
			mListener = (MyListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(getActivity().getClass().getName() + " must implements interface MyListener");
		}
	}

	@Override
	public int getlayout() {
		return R.layout.fragment_table;
	}

	@Override
	protected void initView() {
		standCurveBeans = new ArrayList<StandCurveBean>();
		tableFraBeans = new ArrayList<TableFraBean>();
		dataSourceListBlock1 = new ArrayList<HashMap<String, Object>>();
		dataSourceListBlock2 = new ArrayList<HashMap<String, Object>>();
		activityMethodBeans = new ArrayList<MethodBean>();
		dataListCTArrayList = new HashMap<Integer, LineDataSet>();
		getInfo();
		if (repititions == 0) {
			// 不能使用此页面
			white_line.setVisibility(View.VISIBLE);
			return;
		} else if (repititions == 1) {

			// 不能使用此页面
			white_line.setVisibility(View.VISIBLE);
			return;
		}else {
			white_line.setVisibility(View.GONE);
		}
		
		AmplificationUtil amplificationUtil = new AmplificationUtil();
		amplificationUtil.getAnalySetting(getActivity(), dataSourceListBlock1, dataSourceListBlock2, repititions,
				AnalyzeAmplificationplotActivity.getInstence().dataListArrayList);
		dataListCTArrayList = amplificationUtil.getDataListCTArrayList();
		for (int i = 0; i < activityLayoutTableBeans.size(); i++) {

			standCurveBeans.add(new StandCurveBean(activityLayoutTableBeans.get(i).getTarget(), "", "", "", ""));

		}
		if (experimentType.equals("标准曲线相对定量") || experimentType.equals("Standard Curve Relative Quantitation")) {

		} else {
			getStandCurveBeans();
		}

		getTableFragmentBean();

		for (Integer i : ((AnalyzeRawDataTwoActivity) getActivity()).positionsArrayList) {

			tableFraBeans.get(i).setOmit(true);
		}
	}

	private void getTableFragmentBean() {
		getStandCurveBeans();
		tableFraBeans.clear();
		for (int i = 0; i < 32; i++) {
			String num = "";
			num = i + 1 + "";
			String well = "";
			if (i < 8) {
				int linshi = i + 1;
				well = "A" + linshi;
			} else if (i >= 8 && i < 16) {
				int linshi = i - 7;
				well = "B" + linshi;
			} else if (i >= 16 && i < 24) {
				int linshi = i - 15;
				well = "C" + linshi;
			} else if (i >= 24 && i < 32) {
				int linshi = i - 23;
				well = "D" + linshi;
			}

			String flag = "";
			String sampleName = "";
			if (i < 16) {
				sampleName = dataSourceListBlock1.get(i).get("item_text") + "";
			} else {
				sampleName = dataSourceListBlock2.get(i - 16).get("item_text") + "";
			}
			String targetName = "";
			if (i < 16) {
				for (int j = 0; j < activityLayoutTableBeans.size(); j++) {
					if (TextUtils.isEmpty(dataSourceListBlock1.get(i).get("item_image") + "")) {

					} else {
						if (activityLayoutTableBeans.get(j)
								.getColor() == (Integer.parseInt(dataSourceListBlock1.get(i).get("item_image") + ""))) {
							targetName = activityLayoutTableBeans.get(j).getTarget();
						}
					}

				}

			} else {
				for (int j = 0; j < activityLayoutTableBeans.size(); j++) {
					if (TextUtils.isEmpty(dataSourceListBlock2.get(i - 16).get("item_image") + "")) {

					} else {
						if (activityLayoutTableBeans.get(j).getColor() == (Integer
								.parseInt(dataSourceListBlock2.get(i - 16).get("item_image") + ""))) {
							targetName = activityLayoutTableBeans.get(j).getTarget();
						}
					}

				}
			}
			String task = "";
			if (i < 16) {
				task = dataSourceListBlock1.get(i).get("item_type") + "";
			} else {
				task = dataSourceListBlock2.get(i - 16).get("item_type") + "";
			}
			if ("null".equals(task)) {
				sampleName = "";
			}
			String dyes = "";
			if (i < 16) {
				for (int j = 0; j < activityLayoutTableBeans.size(); j++) {
					if (TextUtils.isEmpty(dataSourceListBlock1.get(i).get("item_image") + "")) {

					} else {
						if (activityLayoutTableBeans.get(j)
								.getColor() == (Integer.parseInt(dataSourceListBlock1.get(i).get("item_image") + ""))) {
							dyes = activityLayoutTableBeans.get(j).getFluorescentDyes();
						}
					}

				}

			} else {
				for (int j = 0; j < activityLayoutTableBeans.size(); j++) {
					if (TextUtils.isEmpty(dataSourceListBlock2.get(i - 16).get("item_image") + "")) {

					} else {
						if (activityLayoutTableBeans.get(j).getColor() == (Integer
								.parseInt(dataSourceListBlock2.get(i - 16).get("item_image") + ""))) {
							dyes = activityLayoutTableBeans.get(j).getFluorescentDyes();
						}
					}

				}
			}
			DecimalFormat fnum3Wei = new DecimalFormat("##0.000");

			String ct = "";// dande

			if ("sample".equals(task) || "standard".equals(task)) {
				ct = fnum3Wei.format(dataListCTArrayList.get(i).getYValForXIndex(i)) + "";
			}

			// String ctMean = "";// pinfjunzhi
			// int count = 0;
			// double totalCT = 0;
			// for (int j = 0; j < 32; j++) {
			//
			// if (j < 16) {
			// if (sampleName.equals(dataSourceListBlock1.get(j).get(
			// "item_text"))) {
			// totalCT = totalCT
			// + dataListCTArrayList.get(j)
			// .getYValForXIndex(j);
			// count++;
			// }
			//
			// } else {
			// if (sampleName.equals(dataSourceListBlock2.get(j - 16).get(
			// "item_text"))) {
			// totalCT = totalCT
			// + dataListCTArrayList.get(j)
			// .getYValForXIndex(j);
			// count++;
			// }
			//
			// }
			// }
			// ctMean = fnum3Wei.format((totalCT / count)) + "";
			// if ("null".equals(task)) {
			// ctMean = "";
			// }
			// String ctSD = "";// fangcha
			// int[] array = new int[count];
			// int linshi = 0;
			// for (int j = 0; j < 32; j++) {
			//
			// if (j < 16) {
			// if (sampleName.equals(dataSourceListBlock1.get(j).get(
			// "item_text"))) {
			// // totalCT = totalCT
			// // + dataListCTArrayList.get(i)
			// // .getYValForXIndex(i);
			// // count++;
			//
			// array[linshi] = (int) dataListCTArrayList.get(j)
			// .getYValForXIndex(j);
			// linshi++;
			//
			// }
			//
			// } else {
			// if (sampleName.equals(dataSourceListBlock2.get(j - 16).get(
			// "item_text"))) {
			// // totalCT = totalCT
			// // + dataListCTArrayList.get(i)
			// // .getYValForXIndex(i);
			// // count++;
			// array[linshi] = (int) dataListCTArrayList.get(j)
			// .getYValForXIndex(j);
			// linshi++;
			//
			// }
			//
			// }
			// }
			// BiaoZhunCha biaoZhunCha = new BiaoZhunCha(array, array.length);
			// ctSD = fnum3Wei.format(biaoZhunCha.getStandardDevition()) + "";
			// if ("null".equals(task) || "NaN".equals(ctSD)) {
			// ctSD = "";
			// }
			String quantity = "";// 标准曲线xzhou
			String efficiency = "";
			String slop = "";

			String normalizedQuantitySE = "";//

			String rQ = "";//
			if (experimentType.equals("绝对定量") || experimentType.equals("Absolute Quantitation")) {
				quantity = "";// 标准曲线xzhou
				efficiency = "";
				slop = "";
				ArrayList<String> colors = new ArrayList<String>();
				for (LayoutTableBean tableBean : activityLayoutTableBeans) {
					colors.add(tableBean.getColor() + "");

				}
				if ("sample".equals(task)) {
					Boolean flaglinshi = false;
					for (int x = 0; x < colors.size(); x++) {
						if (hashMap2.get(colors.get(x)).size() > 1) {
							flaglinshi = true;
						}
					}
					if (!flaglinshi) {

					} else {

						for (int j = 0; j < colors.size(); j++) {
							if (i < 16) {
								//

								if (dataSourceListBlock1.get(i).get("item_image").equals(colors.get(j))) {
									efficiency = fnum3Wei
											.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
									slop = fnum3Wei.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));
									for (int x = 0; x < smpleYValeueArrayList.size(); x++) {
										if (smpleYValeueArrayList.get(x)
												.equals(dataListCTArrayList.get(i).getYValForXIndex(i) + "")) {

											double f = Math.pow(10, linshiList.get(x));
											try {
												BigDecimal b = new BigDecimal(f);
												quantity = b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
											} catch (Exception e) {
												// TODO: handle exception
												quantity = f+"";
											}
											

											// try {
											//
											// quantity = fnum3Wei
											// .parse(Double.parseDouble(Math
											// .pow(10,
											// linshiList
											// .get(x))
											// + "")
											// + "")
											// + "";
											// } catch (NumberFormatException e)
											// {
											// // TODO Auto-generated catch
											// // block
											// e.printStackTrace();
											// } catch (ParseException e) {
											// // TODO Auto-generated catch
											// // block
											// e.printStackTrace();
											// }
											break;
										}
									}
								}

							} else {

								if (dataSourceListBlock2.get(i - 16).get("item_image").equals(colors.get(j))) {
									for (int x = 0; x < smpleYValeueArrayList.size(); x++) {
										efficiency = fnum3Wei
												.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
										slop = fnum3Wei
												.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));
										if (smpleYValeueArrayList.get(x)
												.equals(dataListCTArrayList.get(i).getYValForXIndex(i) + "")) {

											double f = Math.pow(10, linshiList.get(x));
											BigDecimal b = new BigDecimal(f);
											quantity = b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

											// try {
											// quantity = fnum3Wei
											// .parse(Double.parseDouble(Math
											// .pow(10,
											// linshiList
											// .get(x))
											// + "")
											// + "")
											// + "";
											// } catch (NumberFormatException e)
											// {
											// // TODO Auto-generated catch
											// // block
											// e.printStackTrace();
											// } catch (ParseException e) {
											// // TODO Auto-generated catch
											// // block
											// e.printStackTrace();
											// }
											break;
										}
									}

								}
							}
						}
					}

				} else if ("standard".equals(task)) {
					String linshiString = sampleName.substring(sampleName.indexOf("St.") + 3, sampleName.length());
					double a = Double.parseDouble(linshiString.substring(0, linshiString.indexOf("E")));
					double b = Math.pow(10, Integer
							.parseInt(linshiString.substring(linshiString.indexOf("E") + 1, linshiString.length())));

					try {
						quantity = fnum3Wei.parse(Double.parseDouble(a * b + "") + "") + "";
					} catch (NumberFormatException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					for (int j = 0; j < colors.size(); j++) {
						if (i < 16) {
							//

							if (dataSourceListBlock1.get(i).get("item_image").equals(colors.get(j))) {
								if(TextUtils.isEmpty(standCurveBeans.get(j).getEffString() + "")){
									efficiency="";
								}else {
									
									efficiency = fnum3Wei
											.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
								}
								if(TextUtils.isEmpty(standCurveBeans.get(j).getSlope() + "")){
									slop="";
								}else {
									
									slop = fnum3Wei.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));
								}

							}

						} else {

							if (dataSourceListBlock2.get(i - 16).get("item_image").equals(colors.get(j))) {
								for (int x = 0; x < smpleYValeueArrayList.size(); x++) {
									if(TextUtils.isEmpty(standCurveBeans.get(j).getEffString() + "")){
										efficiency="";
									}else {
										
										efficiency = fnum3Wei
												.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
									}
									if(TextUtils.isEmpty(standCurveBeans.get(j).getSlope() + "")){
										slop="";
									}else {
										
										slop = fnum3Wei.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));
									}

								}

							}
						}
					}
				}

			} else if (experimentType.equals("标准曲线相对定量")
					|| experimentType.equals("Standard Curve Relative Quantitation")) {
				quantity = "";// 标准曲线xzhou
				efficiency = "";
				slop = "";
				ArrayList<String> colors = new ArrayList<String>();
				for (LayoutTableBean tableBean : activityLayoutTableBeans) {
					colors.add(tableBean.getColor() + "");

				}
				if ("sample".equals(task)) {
					Boolean flaglinshi = false;
					for (int x = 0; x < colors.size(); x++) {
						if (hashMap2.get(colors.get(x)).size() > 1) {
							flaglinshi = true;
						}
					}
					if (!flaglinshi) {

					} else {

						for (int j = 0; j < colors.size(); j++) {
							if (i < 16) {
								//

								if (dataSourceListBlock1.get(i).get("item_image").equals(colors.get(j))) {
									efficiency = fnum3Wei
											.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
									slop = fnum3Wei.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));
									for (int x = 0; x < smpleYValeueArrayList.size(); x++) {
										if (smpleYValeueArrayList.get(x)
												.equals(dataListCTArrayList.get(i).getYValForXIndex(i) + "")) {

											quantity = Math.pow(10, linshiList.get(x)) + "";
											break;
										}
									}
								}

							} else {

								if (dataSourceListBlock2.get(i - 16).get("item_image").equals(colors.get(j))) {
									for (int x = 0; x < smpleYValeueArrayList.size(); x++) {
										efficiency = fnum3Wei
												.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
										slop = fnum3Wei
												.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));
										if (smpleYValeueArrayList.get(x)
												.equals(dataListCTArrayList.get(i).getYValForXIndex(i) + "")) {
											quantity = Math.pow(10, linshiList.get(x)) + "";
											break;
										}
									}

								}
							}
						}
					}

				} else if ("standard".equals(task)) {
					String linshiString = sampleName.substring(sampleName.indexOf("St.") + 3, sampleName.length());
					double a = Double.parseDouble(linshiString.substring(0, linshiString.indexOf("E")));
					double b = Math.pow(10, Integer
							.parseInt(linshiString.substring(linshiString.indexOf("E") + 1, linshiString.length())));

					quantity = a * b + "";

					for (int j = 0; j < colors.size(); j++) {
						if (i < 16) {
							//

							if (dataSourceListBlock1.get(i).get("item_image").equals(colors.get(j))) {
								efficiency = fnum3Wei
										.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
								slop = fnum3Wei.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));

							}

						} else {

							if (dataSourceListBlock2.get(i - 16).get("item_image").equals(colors.get(j))) {
								for (int x = 0; x < smpleYValeueArrayList.size(); x++) {
									efficiency = fnum3Wei
											.format(Double.parseDouble(standCurveBeans.get(j).getEffString() + ""));
									slop = fnum3Wei.format(Double.parseDouble(standCurveBeans.get(j).getSlope() + ""));

								}

							}
						}
					}
				}

				// endogenousControl;
				// referenceSample;

				// 先检验 基因盘有没有两种target 和两种Sample 没有就rQ系列就为空
				for (int x = 0; x < 16; x++) {
					int color = 0;
					for (int y = 0; y < activityLayoutTableBeans.size(); y++) {
						if (endogenousControl.equals(activityLayoutTableBeans.get(y).getTarget())) {
							color = activityLayoutTableBeans.get(y).getColor();
						}
					}
					if ((dataSourceListBlock1.get(x).get("item_image").equals(color + ""))) {
						if (referenceSample.equals(dataSourceListBlock1.get(x).get("item_text"))) {
							// a1 ：dataSourceListBlock1.get(x)
							for (int n = 0; n < 16; n++) {
								// 找出target跟他一样的
								if ((dataSourceListBlock1.get(x).get("item_image").equals(color + ""))) {

								} else {

								}
								if ((dataSourceListBlock1.get(x).get("item_image").equals(color + ""))) {

								}
							}
						} else {
							// rq等为空
						}
					} else {
						// rq等为空
					}
					if ((dataSourceListBlock2.get(x).get("item_image").equals(color + ""))) {

					} else {
						// rq等为空
					}
				}

			} else if (experimentType.equals("比较ct值相对定量") || experimentType.equals("⊿Ct Relative Quantitation")) {
				// quantityTv, norquantityTv, norsequantityTv
				quantityTv.setText("⊿CtMean");
				norquantityTv.setText("⊿CtSE");
				norsequantityTv.setText("⊿⊿Ct");
			}
			String rQMin = "";
			String rqMax = "";
			String mighsd = "";
			String comments = "";
			tableFraBeans.add(new TableFraBean(num, well, flag, sampleName, targetName, task, dyes, ct, "", "",
					quantity, normalizedQuantitySE, efficiency, slop, rQ, rQMin, rqMax, mighsd, comments));
		}

		if (experimentType.equals("标准曲线相对定量") || experimentType.equals("Standard Curve Relative Quantitation")) {
			getStandardRq();

		} else if (experimentType.equals("比较ct值相对定量") || experimentType.equals("⊿Ct Relative Quantitation")) {
			getCTRq();
			getCtCtRq();
		}

		for (int i = 0; i < 32; i++) {
			String ctMean = "";// pinfjunzhi
			int count = 0;
			double totalCT = 0;
			for (int j = 0; j < 32; j++) {

				if (j < 16) {
					if (tableFraBeans.get(i).getSampleName().equals(dataSourceListBlock1.get(j).get("item_text"))) {
						totalCT = totalCT + dataListCTArrayList.get(j).getYValForXIndex(j);
						count++;
					}

				} else {
					if (tableFraBeans.get(i).getSampleName()
							.equals(dataSourceListBlock2.get(j - 16).get("item_text"))) {
						totalCT = totalCT + dataListCTArrayList.get(j).getYValForXIndex(j);
						count++;
					}

				}

			}
			DecimalFormat fnum3Wei = new DecimalFormat("##0.000");
			ctMean = fnum3Wei.format((totalCT / count)) + "";
			if ("null".equals(tableFraBeans.get(i).getTask())) {
				ctMean = "";
			}
			tableFraBeans.get(i).setCtMean(ctMean);

			String ctSD = "";// fangcha
			float[] array = new float[count];
			int linshi = 0;
			for (int j = 0; j < 32; j++) {

				if (j < 16) {
					if (tableFraBeans.get(i).getSampleName().equals(dataSourceListBlock1.get(j).get("item_text"))) {
						// totalCT = totalCT
						// + dataListCTArrayList.get(i)
						// .getYValForXIndex(i);
						// count++;

						array[linshi] = dataListCTArrayList.get(j).getYValForXIndex(j);
						linshi++;

					}

				} else {
					if (tableFraBeans.get(i).getSampleName()
							.equals(dataSourceListBlock2.get(j - 16).get("item_text"))) {
						// totalCT = totalCT
						// + dataListCTArrayList.get(i)
						// .getYValForXIndex(i);
						// count++;
						array[linshi] = dataListCTArrayList.get(j).getYValForXIndex(j);
						linshi++;

					}

				}
			}
			BiaoZhunCha biaoZhunCha = new BiaoZhunCha(array, array.length);
			ctSD = fnum3Wei.format(biaoZhunCha.getStandardDevition()) + "";
			if ("null".equals(tableFraBeans.get(i).getTask()) || "NaN".equals(ctSD)) {
				ctSD = "";
			}
			tableFraBeans.get(i).setCtSD(ctSD);
		}
		tableFraBeansShow.clear();
		tableFraBeansShow.addAll(tableFraBeans);
	}

	private void getCtCtRq() {
		// private String endogenousControl;
		// private String referenceSample;

		for (int i = 0; i < 32; i++) {
			if ("sample".equals(tableFraBeans.get(i).getTask())) {
				if (!endogenousControl.equals(tableFraBeans.get(i).getTargetName())) {
					if (!referenceSample.equals(tableFraBeans.get(i).getSampleName())) {
						for (int j = 0; j < 32; j++) {
							if (tableFraBeans.get(i).getTargetName().equals(tableFraBeans.get(j).getTargetName())) {
								if (referenceSample.equals(tableFraBeans.get(j).getSampleName())) {
									tableFraBeans.get(i).setNormalizedQuantitySE(
											Double.parseDouble(tableFraBeans.get(i).getQuantity())
													- Double.parseDouble(tableFraBeans.get(j).getQuantity()) + "");
									tableFraBeans.get(i)
											.setrQ(Math.pow(10,
													-Double.parseDouble(tableFraBeans.get(i).getNormalizedQuantitySE()))
													+ "");
								}
							}
						}
					}
				}
			}
		}
	}

	private void getCTRq() {

		// endogenousControl;
		// referenceSample;

		// 先判断上面的两个参数在基因盘中是否有。
		// 如果没有就不用往下进行了
		Boolean continueFlag = false;
		ArrayList<String> colors = new ArrayList<String>();
		HashSet<String> sampleSet = new HashSet<String>();
		for (LayoutTableBean tableBean : activityLayoutTableBeans) {
			colors.add(tableBean.getColor() + "");
		}
		for (int i = 0; i < 16; i++) {

			if (referenceSample.equals(dataSourceListBlock1.get(i).get("item_text"))) {
				for (int j = 0; j < colors.size(); j++) {
					if (colors.get(j).equals(dataSourceListBlock1.get(i).get("item_image"))) {
						if (endogenousControl.equals(activityLayoutTableBeans.get(j).getTarget())) {
							continueFlag = true;
						}
					}
				}
			}
			if (referenceSample.equals(dataSourceListBlock2.get(i).get("item_text"))) {
				for (int j = 0; j < colors.size(); j++) {
					if (colors.get(j).equals(dataSourceListBlock2.get(i).get("item_image"))) {
						if (endogenousControl.equals(activityLayoutTableBeans.get(j).getTarget())) {
							continueFlag = true;
						}
					}
				}
			}

		}

		// 先找到Sample所有的sample类型
		sampleSet = new HashSet<String>();

		for (int i = 0; i < 16; i++) {
			if ("sample".equals(dataSourceListBlock1.get(i).get("item_type"))) {
				sampleSet.add(dataSourceListBlock1.get(i).get("item_text") + "");
			}
			if ("sample".equals(dataSourceListBlock2.get(i).get("item_type"))) {
				sampleSet.add(dataSourceListBlock2.get(i).get("item_text") + "");
			}
		}

		for (String ss : sampleSet) {
			Boolean boolean1 = false;
			for (int i = 0; i < 16; i++) {
				if (ss.equals(dataSourceListBlock1.get(i).get("item_text"))) {
					for (int j = 0; j < activityLayoutTableBeans.size(); j++) {
						if (activityLayoutTableBeans.get(j).getColor() == Integer
								.parseInt(dataSourceListBlock1.get(i).get("item_image") + "")) {
							if (endogenousControl.equals(activityLayoutTableBeans.get(j).getTarget())) {
								boolean1 = true;
							}

						}
					}
				}
				if (ss.equals(dataSourceListBlock2.get(i).get("item_text"))) {
					for (int j = 0; j < activityLayoutTableBeans.size(); j++) {
						if (activityLayoutTableBeans.get(j).getColor() == Integer
								.parseInt(dataSourceListBlock2.get(i).get("item_image") + "")) {
							if (endogenousControl.equals(activityLayoutTableBeans.get(j).getTarget())) {
								boolean1 = true;
							}

						}
					}
				}
			}
			if (boolean1) {

			} else {
				continueFlag = false;
			}
		}

		if (continueFlag) {
			// 有数据 继续往下做
			// ⊿Ct ----target分
			// 先分类所有sample 和target的
			HashSet<ArrayList<String>> sampleNamesSet = new HashSet<ArrayList<String>>();
			// HashMap<String, ArrayList<Integer>> samplePositionHashMap = new
			// HashMap<String, ArrayList<Integer>>();
			// sample -- target(color) -- position
			HashMap<String, HashMap<String, ArrayList<Integer>>> resultMap = new HashMap<String, HashMap<String, ArrayList<Integer>>>();

			for (int i = 0; i < 16; i++) {

				if ("sample".equals(dataSourceListBlock1.get(i).get("item_type"))) {

					for (int j = 0; j < colors.size(); j++) {

						if (colors.get(j).equals(dataSourceListBlock1.get(i).get("item_image"))) {
							// sample --target(color
							ArrayList<String> linshiKeyArrayList = new ArrayList<String>();
							linshiKeyArrayList.add(dataSourceListBlock1.get(i).get("item_text") + "");
							linshiKeyArrayList.add(dataSourceListBlock1.get(i).get("item_image") + "");
							sampleNamesSet.add(linshiKeyArrayList);

							if (resultMap.get(dataSourceListBlock1.get(i).get("item_text") + "") != null) {

								if (resultMap.get(dataSourceListBlock1.get(i).get("item_text") + "")
										.get(dataSourceListBlock1.get(i).get("item_image") + "") != null) {

									HashMap<String, ArrayList<Integer>> linshiTaget = new HashMap<String, ArrayList<Integer>>();
									linshiTaget = resultMap.get(dataSourceListBlock1.get(i).get("item_text") + "");
									ArrayList<Integer> linshipositionArrayList = new ArrayList<Integer>();
									linshipositionArrayList = resultMap
											.get(dataSourceListBlock1.get(i).get("item_text") + "")
											.get(dataSourceListBlock1.get(i).get("item_image") + "");
									linshipositionArrayList.add(i);
									linshiTaget.put(dataSourceListBlock1.get(i).get("item_image") + "",
											linshipositionArrayList);
									resultMap.put(dataSourceListBlock1.get(i).get("item_text") + "", linshiTaget);

								} else {
									HashMap<String, ArrayList<Integer>> linshiTaget = new HashMap<String, ArrayList<Integer>>();
									linshiTaget = resultMap.get(dataSourceListBlock1.get(i).get("item_text") + "");
									ArrayList<Integer> linshipositionArrayList = new ArrayList<Integer>();
									linshipositionArrayList.add(i);
									linshiTaget.put(dataSourceListBlock1.get(i).get("item_image") + "",
											linshipositionArrayList);
									resultMap.put(dataSourceListBlock1.get(i).get("item_text") + "", linshiTaget);

								}
							} else {
								HashMap<String, ArrayList<Integer>> linshiTaget = new HashMap<String, ArrayList<Integer>>();
								ArrayList<Integer> linshipositionArrayList = new ArrayList<Integer>();
								linshipositionArrayList.add(i);
								linshiTaget.put(dataSourceListBlock1.get(i).get("item_image") + "",
										linshipositionArrayList);
								resultMap.put(dataSourceListBlock1.get(i).get("item_text") + "", linshiTaget);

							}
						}
					}
					// if (samplePositionHashMap.get(dataSourceListBlock1.get(i)
					// .get("item_text") + "") != null) {
					// ArrayList<Integer> linshiPositionArrayList = new
					// ArrayList<Integer>();
					// linshiPositionArrayList = samplePositionHashMap
					// .get(dataSourceListBlock1.get(i).get(
					// "item_text")
					// + "");
					// linshiPositionArrayList.add(i);
					// samplePositionHashMap
					// .put(dataSourceListBlock1.get(i).get(
					// "item_text")
					// + "", linshiPositionArrayList);
					//
					//
					// } else {
					// ArrayList<Integer> linshiPositionArrayList = new
					// ArrayList<Integer>();
					// linshiPositionArrayList.add(i);
					// samplePositionHashMap
					// .put(dataSourceListBlock1.get(i).get(
					// "item_text")
					// + "", linshiPositionArrayList);
					// }
				}

				if ("sample".equals(dataSourceListBlock2.get(i).get("item_type"))) {

					for (int j = 0; j < colors.size(); j++) {

						if (colors.get(j).equals(dataSourceListBlock2.get(i).get("item_image"))) {
							// sample --target(color
							ArrayList<String> linshiKeyArrayList = new ArrayList<String>();
							linshiKeyArrayList.add(dataSourceListBlock2.get(i).get("item_text") + "");
							linshiKeyArrayList.add(dataSourceListBlock2.get(i).get("item_image") + "");
							sampleNamesSet.add(linshiKeyArrayList);

							if (resultMap.get(dataSourceListBlock2.get(i).get("item_text") + "") != null) {

								if (resultMap.get(dataSourceListBlock2.get(i).get("item_text") + "")
										.get(dataSourceListBlock2.get(i).get("item_image") + "") != null) {

									HashMap<String, ArrayList<Integer>> linshiTaget = new HashMap<String, ArrayList<Integer>>();
									linshiTaget = resultMap.get(dataSourceListBlock2.get(i).get("item_text") + "");
									ArrayList<Integer> linshipositionArrayList = new ArrayList<Integer>();
									linshipositionArrayList = resultMap
											.get(dataSourceListBlock2.get(i).get("item_text") + "")
											.get(dataSourceListBlock2.get(i).get("item_image") + "");
									linshipositionArrayList.add(i + 16);
									linshiTaget.put(dataSourceListBlock2.get(i).get("item_image") + "",
											linshipositionArrayList);
									resultMap.put(dataSourceListBlock2.get(i).get("item_text") + "", linshiTaget);

								} else {
									HashMap<String, ArrayList<Integer>> linshiTaget = new HashMap<String, ArrayList<Integer>>();
									linshiTaget = resultMap.get(dataSourceListBlock2.get(i).get("item_text") + "");
									ArrayList<Integer> linshipositionArrayList = new ArrayList<Integer>();
									linshipositionArrayList.add(i + 16);
									linshiTaget.put(dataSourceListBlock2.get(i).get("item_image") + "",
											linshipositionArrayList);
									resultMap.put(dataSourceListBlock2.get(i).get("item_text") + "", linshiTaget);

								}
							} else {
								HashMap<String, ArrayList<Integer>> linshiTaget = new HashMap<String, ArrayList<Integer>>();
								ArrayList<Integer> linshipositionArrayList = new ArrayList<Integer>();
								linshipositionArrayList.add(i + 16);
								linshiTaget.put(dataSourceListBlock2.get(i).get("item_image") + "",
										linshipositionArrayList);
								resultMap.put(dataSourceListBlock2.get(i).get("item_text") + "", linshiTaget);

							}
						}
					}

				}

			}
			// 先分类所有sample 和target的
			// sampleNamesSet
			// sample -- target(color) -- position
			// resultMap
			// 分类相同的取ct的平均值
			ArrayList<Double> avgArrayList = new ArrayList<Double>();
			for (ArrayList<String> little : sampleNamesSet) {
				double sum = 0;
				for (int i = 0; i < resultMap.get(little.get(0)).get(little.get(1)).size(); i++) {
					int position = resultMap.get(little.get(0)).get(little.get(1)).get(i);

					sum = sum + dataListCTArrayList.get(position).getYValForXIndex(position);

				}
				double avg = sum / resultMap.get(little.get(0)).get(little.get(1)).size();
				avgArrayList.add(avg);
			}

			// 找出基准的那个平均值
			// endogenousControl;
			// referenceSample;

			String endogString = "";
			for (int i = 0; i < activityLayoutTableBeans.size(); i++) {
				if (endogenousControl.equals(activityLayoutTableBeans.get(i).getTarget())) {
					endogString = activityLayoutTableBeans.get(i).getColor() + "";
					break;
				}
			}
			double JIZHUN = 0;
			for (int i = 0; i < 16; i++) {
				for (String ss : sampleSet) {
					if (ss.equals(dataSourceListBlock1.get(i).get("item_text"))) {
						if (endogString.equals(dataSourceListBlock1.get(i).get("item_image"))) {
							// 基准的
							int count = 0;
							for (ArrayList<String> little : sampleNamesSet) {
								if (ss.equals(little.get(0))) {
									if (endogString.equals(little.get(1))) {
										break;
									}
								}
								count++;
							}
							JIZHUN = avgArrayList.get(count);

						}
					}
					if (ss.equals(dataSourceListBlock2.get(i).get("item_text"))) {
						if (endogString.equals(dataSourceListBlock2.get(i).get("item_image"))) {
							// 基准的
							int count = 0;
							for (ArrayList<String> little : sampleNamesSet) {
								if (ss.equals(little.get(0))) {
									if (endogString.equals(little.get(1))) {
										break;
									}
								}
								count++;
							}
							JIZHUN = avgArrayList.get(count);

						}
					}
				}

			}

			for (int i = 0; i < 32; i++) {
				if ("sample".equals(tableFraBeans.get(i).getTask())) {

					if (endogenousControl.equals(tableFraBeans.get(i).getTargetName())) {

					} else {
						int count = 0;
						for (ArrayList<String> little : sampleNamesSet) {
							if (tableFraBeans.get(i).getSampleName().equals(little.get(0))) {
								String targetNameString = "";
								for (int x = 0; x < activityLayoutTableBeans.size(); x++) {
									if (activityLayoutTableBeans.get(x).getColor() == Integer.parseInt(little.get(1))) {
										targetNameString = activityLayoutTableBeans.get(x).getTarget();
										break;
									}
								}
								if (tableFraBeans.get(i).getTargetName().equals(targetNameString)) {
									break;
								}
							}
							count++;
						}
						tableFraBeans.get(i).setQuantity(avgArrayList.get(count) - JIZHUN + "");
					}

				}

			}
			// String endogString = "";
			// for (int i = 0; i < activityLayoutTableBeans.size(); i++) {
			// if (endogenousControl.equals(activityLayoutTableBeans.get(i)
			// .getTarget())) {
			// endogString = activityLayoutTableBeans.get(i).getColor()
			// + "";
			// break;
			// }
			// }
			// int count = 0;
			// for (ArrayList<String> little : sampleNamesSet) {
			// if (referenceSample.equals(little.get(0))) {
			// if (endogString.equals(little.get(1))) {
			//
			// break;
			// }
			// }
			// count++;
			// }
			// double JIZHUN = avgArrayList.get(count);
			// count = 0;
			// for (ArrayList<String> little : sampleNamesSet) {
			//
			// for (int i = 0; i < resultMap.get(little.get(0))
			// .get(little.get(1)).size(); i++) {
			// int position = resultMap.get(little.get(0))
			// .get(little.get(1)).get(i);
			// tableFraBeans.get(position).setQuantity(
			// avgArrayList.get(count) - JIZHUN + "");
			// }
			// count++;
			// }

		} else {
			// 没有数据
		}

	}

	private void getStandCurveBeans() {

		//
		// dataListCTArrayList =
		// AnalyzeAmplificationplotActivity.getInstence().dataListCTArrayList;
		// 分别遍历两个基因盘数据

		// ArrayList<HashMap<String, ArrayList<String>>> targetGenenArrayList =
		// new ArrayList<HashMap<String, ArrayList<String>>>();

		ArrayList<String> colors = new ArrayList<String>();
		for (LayoutTableBean tableBean : activityLayoutTableBeans) {
			colors.add(tableBean.getColor() + "");
		}
		HashMap<String, ArrayList<String>> hashMap = new HashMap<String, ArrayList<String>>();
		hashMap2 = new HashMap<String, HashSet<String>>();
		for (int j = 0; j < colors.size(); j++) {

			ArrayList<String> strings = new ArrayList<String>();
			// 求个数用的,排除重复
			HashSet<String> Stringset = new HashSet<String>();

			for (int y = 0; y < 16; y++) {

				// ab
				if (dataSourceListBlock1.get(y).get("item_image").equals(colors.get(j))) {
					if ("standard".equals(dataSourceListBlock1.get(y).get("item_type"))) {
						strings.add(dataSourceListBlock1.get(y).get("item_text") + "");
						Stringset.add(dataSourceListBlock1.get(y).get("item_text") + "");
					}

				}
				// cd
				if (dataSourceListBlock2.get(y).get("item_image").equals(colors.get(j))) {
					if ("standard".equals(dataSourceListBlock2.get(y).get("item_type"))) {
						strings.add(dataSourceListBlock2.get(y).get("item_text") + "");
						Stringset.add(dataSourceListBlock2.get(y).get("item_text") + "");
					}

				}

			}

			hashMap.put(colors.get(j), strings);
			hashMap2.put(colors.get(j), Stringset);
		}

		//
		Boolean flaglinshi = false;
		for (int x = 0; x < colors.size(); x++) {
			if (hashMap2.get(colors.get(x)).size() > 1) {
				flaglinshi = true;
			}
		}

		if (flaglinshi) {
			// 可以使用此页面

			// 红点的x轴数据
			HashMap<String, ArrayList<Double>> xValuesDoubleSetHashMap = new HashMap<String, ArrayList<Double>>();

			// 加入红色standard点的x轴值

			for (int x = 0; x < colors.size(); x++) {
				ArrayList<Double> xValuesDouble = new ArrayList<Double>();
				for (String setString : hashMap2.get(colors.get(x))) {
					String linshiString = setString.substring(setString.indexOf("St.") + 3, setString.length());
					xValuesDouble
							.add(MathLog.log(
									(float) (Float.parseFloat(linshiString.substring(0, linshiString.indexOf("E")))
											* (Math.pow(10,
													Integer.parseInt(linshiString.substring(
															linshiString.indexOf("E") + 1, linshiString.length()))))),
							10));
				}
				xValuesDoubleSetHashMap.put(colors.get(x), xValuesDouble);
			}
			ArrayList<Double> xValueAllArrayList = new ArrayList<Double>();

			for (int x = 0; x < colors.size(); x++) {
				if (xValuesDoubleSetHashMap.get(colors.get(x)).size() > 1) {
					xValueAllArrayList.addAll(xValuesDoubleSetHashMap.get(colors.get(x)));
				}

			}

			HashMap<String, ArrayList<String>> sssetsetArrayListHashMap = new HashMap<String, ArrayList<String>>();

			for (int colorsNum = 0; colorsNum < colors.size(); colorsNum++) {
				Iterator<String> it = hashMap2.get(colors.get(colorsNum)).iterator();
				ArrayList<String> sssetsetArrayList = new ArrayList<String>();
				while (it.hasNext()) {
					sssetsetArrayList.add(it.next());
				}
				sssetsetArrayListHashMap.put(colors.get(colorsNum), sssetsetArrayList);
			}

			HashMap<String, double[]> pxsHashMap = new HashMap<String, double[]>();
			HashMap<String, double[]> pysHashMap = new HashMap<String, double[]>();

			for (int colorsNum = 0; colorsNum < colors.size(); colorsNum++) {
				double pX[] = new double[xValueAllArrayList.size()];
				double pY[] = new double[xValueAllArrayList.size()];
				for (int x = 0; x < hashMap2.get(colors.get(colorsNum)).size(); x++) {
					if (hashMap2.get(colors.get(colorsNum)).size() > 1) {
						int totalNum = 0;
						double sum = 0;
						pX[x] = xValuesDoubleSetHashMap.get(colors.get(colorsNum)).get(x);
						for (int j = 0; j < 16; j++) {
							if (colors.get(colorsNum).equals(dataSourceListBlock1.get(j).get("item_image"))) {
								if (sssetsetArrayListHashMap.get(colors.get(colorsNum)).get(x)
										.equals(dataSourceListBlock1.get(j).get("item_text"))) {
									sum = sum + dataListCTArrayList.get(j).getYValForXIndex(j);
									totalNum++;
								}
							}
							if (colors.get(colorsNum).equals(dataSourceListBlock2.get(j).get("item_image"))) {
								if (sssetsetArrayListHashMap.get(colors.get(colorsNum)).get(x)
										.equals(dataSourceListBlock2.get(j).get("item_text"))) {
									sum = sum + dataListCTArrayList.get(j + 16).getYValForXIndex(j + 16);
									totalNum++;
								}
							}

						}
						pY[x] = sum / totalNum;
					}

				}
				pxsHashMap.put(colors.get(colorsNum), pX);
				pysHashMap.put(colors.get(colorsNum), pY);
			}

			for (int colorsNum = 0; colorsNum < colors.size(); colorsNum++) {
				Boolean no0 = false;
				for (int x = 0; x < pxsHashMap.get(colors.get(colorsNum)).length; x++) {
					if (pxsHashMap.get(colors.get(colorsNum))[x] != 0) {
						no0 = true;
						break;

					}
				}
				if (no0) {
					if (pxsHashMap.get(colors.get(colorsNum)).length > 1) {
						// ！！！！！！！！！！！！！！！！！！！！
						// ！！！！！！！！！！！！！！！！！！！！
						// ！！！！！！！！！！！！！！！！！！！！
						// 带入了xx 有问题！！！！！！！！！！！！！！！！！！！！！！！！！！
						myLeastSquareMethod.Create(pxsHashMap.get(colors.get(colorsNum)),
								pysHashMap.get(colors.get(colorsNum)), pxsHashMap.get(colors.get(colorsNum)).length);

						// 获取sample的基因盘的ct值

						smpleYValeueArrayList = new ArrayList<String>();
						for (int x = 0; x < 16; x++) {
							if ("sample".equals(dataSourceListBlock1.get(x).get("item_type"))) {
								if (dataSourceListBlock1.get(x).get("item_image").equals(colors.get(colorsNum))) {
									smpleYValeueArrayList.add(dataListCTArrayList.get(x).getYValForXIndex(x) + "");
								}

							}
							if ("sample".equals(dataSourceListBlock2.get(x).get("item_type"))) {

								if (dataSourceListBlock2.get(x).get("item_image").equals(colors.get(colorsNum))) {
									smpleYValeueArrayList
											.add(dataListCTArrayList.get(x + 16).getYValForXIndex(x + 16) + "");
								}

							}
						}
						Set<Double> linshiSet = new HashSet<Double>();
						linshiList = new ArrayList<Double>();

						int[] myCoff = new int[4];
						double k = myLeastSquareMethod.GetSlope(myCoff);
						// myCoff[0]=0表示求解成功，myCoff[0]=2表示求解失败。
						if (myCoff[0] == 2) {
							// 失败

						} else if (myCoff[0] == 0) {
							// 可以使用此页面

							// 成功
							for (String ss : smpleYValeueArrayList) {
								double myXout;
								myXout = myLeastSquareMethod.CalculateXValue(Double.parseDouble(ss));
								linshiSet.add(myXout);
								linshiList.add(myXout);
							}

							Iterator<Double> itSet = linshiSet.iterator();
							while (itSet.hasNext()) {
								xValueAllArrayList.add(itSet.next());
							}
							Collections.sort(xValueAllArrayList);
							// float保留两位小数
							DecimalFormat fnum = new DecimalFormat("##0.00");
							for (int x = 0; x < xValueAllArrayList.size(); x++) {
								xValueAllArrayList.set(x, Double.parseDouble(fnum.format(xValueAllArrayList.get(x))));
							}

							ArrayList<String> xValues = new ArrayList<String>();

							for (int x = 0; x < xValueAllArrayList.size(); x++) {
								Boolean boolean1 = true;
								for (int j = 0; j < xValues.size(); j++) {
									if (xValues.get(j).equals(xValueAllArrayList.get(x) + "")) {
										boolean1 = false;
									}
								}
								if (boolean1) {
									xValues.add(xValueAllArrayList.get(x) + "");
								}

							}

							// b
							double b = myLeastSquareMethod.GetIntercept(myCoff);

							ArrayList<Entry> yValues = new ArrayList<Entry>();

							yValues.add(new Entry((float) (k * Float.parseFloat(xValues.get(0)) + b), 0));
							yValues.add(new Entry((float) (k * Float.parseFloat(xValues.get(xValues.size() - 1)) + b),
									xValues.size() - 1));

							double myXout = 0;
							double myRR = 0;
							double mYintrer = 0;
							double myEff = 0;
							double mySlope = 0;

							mySlope = myLeastSquareMethod.GetSlope(myCoff);// 求直线的K值
							mYintrer = myLeastSquareMethod.GetIntercept(myCoff);// 求直线的y-intercept值
							myRR = myLeastSquareMethod.GetRR(myCoff);// 求直线的RR值
							// Log（1+Eff）=- mySlope ---------------

							standCurveBeans.get(colorsNum).setSlope(mySlope + "");
							standCurveBeans.get(colorsNum).setyInter(mYintrer + "");
							standCurveBeans.get(colorsNum).setR2(myRR + "");
							standCurveBeans.get(colorsNum).setEffString((Math.pow(10, 1 / -mySlope) - 1) * 100 + "");

						}
					}
				} else {
					continue;
				}

			}
		} else {
			// 不能使用此页面

		}

	}

	private void getInfo() {

		//
		folderName = SharedPreferencesUtils.get(getActivity(), BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "";
		fileName = SharedPreferencesUtils.get(getActivity(), BaseApplication.FILEMANGER_PREPAREFILENAME, "") + "";

		String path = appFilePath + "/" + folderName;

		File file = new File(path + "/" + fileName);
		contextString = new StringBuffer();
		
		FileInputStream in =null;
		BufferedReader reader=null;
		contextString=new StringBuffer();
		try {
			in =new FileInputStream(file);
			reader=new BufferedReader(new InputStreamReader(in));
			String line ="";
			while((line =reader.readLine())!=null){
				contextString.append(line);
				contextString.append(",");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(reader != null){
				try {
					reader.close();
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
		}
//		BufferedReader reader = null;
//		contextString=new StringBuffer();
//		System.gc();
//		try {
//			System.out.println("以行为单位读取文件内容，一次读一整行:");
//			reader = new BufferedReader(new FileReader(file));
//			String tempString = null;
//			int line = 1;
//			// 一次读入一行，直到读入null为文件结束
//			while ((tempString = reader.readLine()) != null) {
//				// 显示行号
//				// System.out.println("line " + line + ": " + tempString);
//				// Log.e("--", tempString);
//				contextString.append(tempString);
//				contextString.append(",");
//				line++;
//			}
//			reader.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (reader != null) {
//				try {
//					reader.close();
//					// LogUtil.e("!!", contextString + "");
//
//				} catch (IOException e1) {
//				}
//			}
//		}

		experimentType = contextString.substring(contextString.indexOf("ExperimentType:") + 15,
				contextString.indexOf(",SampleType:")) + "";

		try {
			endogenousControl = contextString.substring(contextString.indexOf(",,endogenousControl:") + 20,
					contextString.indexOf(",referenceSample:"));
			referenceSample = contextString.substring(contextString.indexOf(",referenceSample:") + 17,
					contextString.indexOf(",,cameraSet"));
		} catch (Exception e) {
			// TODO: handle exception
		}

		// layoutOne的数据解析
		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		// LogUtil.e(contextString.indexOf(",Aisle") + 7);
		// LogUtil.e(contextString.indexOf(",Color"));

		int index = 0;
		while (!(contextString.indexOf("Aisle", index) <= 0)) {

			// Aisle:
			String aisle;
			aisle = contextString.substring(contextString.indexOf(",Aisle", index) + 7,

					contextString.indexOf(",Color", index));
					// LogUtil.e(aisle);

			// Color
			String color;
			color = contextString.substring(contextString.indexOf(",Color", index) + 7,

					contextString.indexOf(",Target", index));
					// LogUtil.e(color);

			// Target
			String target;
			target = contextString.substring(contextString.indexOf(",Target", index) + 8,

					contextString.indexOf(",Dyes", index));

			// LogUtil.e(target);

			int nextIndex = contextString.indexOf(",Aisle", index) + 7;

			// Dyes
			String dyes;
			if (contextString.indexOf(",Aisle", nextIndex) < 0) {

				dyes = contextString.substring(contextString.indexOf(",Dyes", index) + 6,
						contextString.indexOf(",,dataSourceListBlock1", index));

				// LogUtil.e(dyes);
			} else {

				dyes = contextString.substring(contextString.indexOf(",Dyes", index) + 6,

						contextString.indexOf(",Aisle", nextIndex));
				// LogUtil.e(dyes);
			}

			index = contextString.indexOf(",Dyes", index) + 5;

			activityLayoutTableBeans.add(new LayoutTableBean(false, Integer.parseInt(aisle.trim()),
					Integer.parseInt(color.trim()), target, dyes));

		}
		index = 0;
		// 上面解析
		while (!(contextString.indexOf("steptType:", index) <= 0)) {

			// steptType:
			String steptType;
			steptType = contextString.substring(contextString.indexOf("steptType:", index) + 10,

					contextString.indexOf(",temperature:", index));

			// LogUtil.e(steptType);

			// temperature
			String temperature;
			temperature = contextString.substring(contextString.indexOf(",temperature:", index) + 13,

					contextString.indexOf(",time:", index));

			// LogUtil.e(temperature);
			// time
			String time;
			time = contextString.substring(contextString.indexOf(",time:", index) + 6,

					contextString.indexOf(",goTo:", index));
					// LogUtil.e(time);

			// goTo
			String goTo;
			goTo = contextString.substring(contextString.indexOf(",goTo:", index) + 6,

					contextString.indexOf(",Repititions:", index));
			// LogUtil.e(goTo);
			// Repititions
			String repititions;
			repititions = contextString.substring(contextString.indexOf(",Repititions:", index) + 13,

					contextString.indexOf(",deltaT:", index));
			// LogUtil.e(repititions);
			// deltaT
			String deltaT;
			deltaT = contextString.substring(contextString.indexOf(",deltaT:", index) + 8,

					contextString.indexOf(",rightSelect:", index));
			// LogUtil.e(deltaT);

			int nextIndex = contextString.indexOf("steptType:", index) + 10;

			// rightSelect
			String rightSelect;

			if (contextString.indexOf(",steptType:", nextIndex) < 0) {
				rightSelect = contextString.substring(contextString.indexOf(",rightSelect:", index) + 13,
						contextString.indexOf(",,pointMap", index));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}

			} else {
				rightSelect = contextString.substring(contextString.indexOf(",rightSelect:", index) + 13,

						contextString.indexOf(",steptType:", nextIndex));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}
			}
			// LogUtil.e(rightSelect);
			index = contextString.indexOf(",rightSelect:", index) + 13;

			activityMethodBeans.add(new MethodBean(steptType.trim(), temperature.trim(), time.trim(), goTo.trim(),
					repititions.trim(), deltaT.trim()));
		}
		// 获取重复次数

		int stepNum = Integer.parseInt(contextString
				.substring(contextString.indexOf(",readDataString: ") + 17, contextString.indexOf(",,Methods")).trim());
		repititionsGet(stepNum);

		index = 0;

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14, contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (i == 15) {
				item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",,dataSourceListBlock2", index)).trim();

			} else {
				item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",item_image:", nextIndex)).trim();
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock1.add(hashMap);
			dataSourceListBlock1Old.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14, contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (contextString.indexOf("item_image:", nextIndex) < 0) {

				// TODO 最后一位不出来颜色bug在这以后再改
				if ("Absolute Quantitation"
						.equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
						| "绝对定量".equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {
					item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",,cameraSet", nextIndex)).trim();
				} else if ("Standard Curve Relative Quantitation"
						.equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
						| "标准曲线相对定量".equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {
					item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",,endogenousControl", nextIndex)).trim();
				} else if ("⊿Ct Relative Quantitation"
						.equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
						| "比较ct值相对定量".equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {
					item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",,endogenousControl", nextIndex)).trim();
				}
				// ByAlert.alert(contextString.substring(
				// contextString.indexOf("item_type:", index) + 10,
				// contextString.length()-1));
			} else {
				if (i == 15) {

				} else {
					item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",item_image:", nextIndex)).trim();
				}
			}

			// LogUtil.e(item_image);
			// LogUtil.e(item_text);
			// LogUtil.e(item_selected);
			// // LogUtil.e(item_null+"");
			// // LogUtil.e(item_aisle+"");
			// LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock2.add(hashMap);
			dataSourceListBlock2Old.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		HashSet<Integer> positionsArrayList = new HashSet<Integer>();
		Gson gson = new Gson();
		String json = "";
		json = (String) SharedPreferencesUtils.get(getActivity(), "positionsArrayList", "");
		Type type = new TypeToken<HashSet<Integer>>() {
		}.getType();
		if (TextUtils.isEmpty(json)) {

		} else {
			positionsArrayList = gson.fromJson(json, type);
		}
		if (positionsArrayList.size() > 0) {
			for (int i : positionsArrayList) {
				if (i < 16) {
					HashMap<String, Object> hashMap = new HashMap<String, Object>();
					hashMap.put("item_image", "");
					hashMap.put("item_text", "");
					hashMap.put("item_selected", false);

					hashMap.put("item_aisle", 0);
					hashMap.put("item_type", "null");
					dataSourceListBlock1.set(i, hashMap);
				} else {
					HashMap<String, Object> hashMap = new HashMap<String, Object>();
					hashMap.put("item_image", "");
					hashMap.put("item_text", "");
					hashMap.put("item_selected", false);

					hashMap.put("item_aisle", 0);
					hashMap.put("item_type", "null");
					dataSourceListBlock2.set(i - 16, hashMap);
				}

			}
		}

		// for (Integer i : ((AnalyzeRawDataTwoActivity)
		// getActivity()).positionsArrayList) {
		//
		// if (i < 16) {
		// HashMap<String, Object> hashMap = new HashMap<String, Object>();
		// hashMap.put("item_image", "");
		// hashMap.put("item_text", "");
		// hashMap.put("item_selected", false);
		//
		// hashMap.put("item_aisle", 0);
		// hashMap.put("item_type", "null");
		// dataSourceListBlock1.set(i, hashMap);
		// } else {
		// HashMap<String, Object> hashMap = new HashMap<String, Object>();
		// hashMap.put("item_image", "");
		// hashMap.put("item_text", "");
		// hashMap.put("item_selected", false);
		//
		// hashMap.put("item_aisle", 0);
		// hashMap.put("item_type", "null");
		// dataSourceListBlock2.set(i - 16, hashMap);
		// }
		// }

	}

	private void repititionsGet(int stepNum) {
		// 先找出拍照的位置
		int cameraStep = stepNum-1;
//		for (MethodBean bean : activityMethodBeans) {
//			if (bean.getRightSelect()) {
//				break;
//			}
//			cameraStep++;
//		}
		ArrayList<ArrayList<Integer>> ranges = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer> littleRange;
		int startStep = 0;
		for (MethodBean bean : activityMethodBeans) {
			if (!TextUtils.isEmpty(bean.getGoTo())) {
				littleRange = new ArrayList<Integer>();
				littleRange.add(startStep);
				littleRange.add(Integer.parseInt(bean.getGoTo())-1);
				ranges.add(littleRange);
			}
			startStep++;
		}

		// 判断有没有跳转
		if (ranges.size() == 0) {
			repititions = 1;
			return;
		} else {
			int sum = 1;
			for (ArrayList<Integer> little : ranges) {
				if (cameraStep <= little.get(0)) {
					if (cameraStep >= little.get(1)) {
						sum = sum * Integer.parseInt(activityMethodBeans.get(little.get(0)).getRepititions());
					}
				}
			}
			repititions = sum;
			return;
		}

	}

	@Override
	protected void dataView() {
		// TODO Auto-generated method stub
		table_list = (ListView) getActivity().findViewById(R.id.table_list);
		show_tv = BindView(R.id.show_tv);
		showPop_List();
	}

	private void showPop_List() {
		tableFraBeansShow.clear();
		if ("⊿Ct Relative Quantitation".equals(SharedPreferencesUtils
				.get(getActivity(),
						BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
						""))
				| "比较ct值相对定量".equals(SharedPreferencesUtils
						.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
								""))) {
			for (int i = 0; i < 32; i++) {
				tableFraBeans.get(i).setQuantity("");
			}

		}
		tableFraBeansShow.addAll(tableFraBeans);
		tableAdapter = new TableAdapter(tableFraBeansShow);

		table_list.setAdapter(tableAdapter);
		show_tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				View view = LayoutInflater.from(getActivity()).inflate(R.layout.show_table, null);
				well_check = (CheckBox) view.findViewById(R.id.well_check);
				Omit_check = (CheckBox) view.findViewById(R.id.Omit_check);
				Sample_check = (CheckBox) view.findViewById(R.id.Sample_check);
				TargetName_check = (CheckBox) view.findViewById(R.id.TargetName_check);
				Task_check = (CheckBox) view.findViewById(R.id.Task_check);
				Dyes_check = (CheckBox) view.findViewById(R.id.Dyes_check);
				Ct_check = (CheckBox) view.findViewById(R.id.Ct_check);
				Ct_Mean_check = (CheckBox) view.findViewById(R.id.Ct_Mean_check);
				Ct_SD_check = (CheckBox) view.findViewById(R.id.Ct_SD_check);
				Quantity_check = (CheckBox) view.findViewById(R.id.Quantity_check);
				SE_check = (CheckBox) view.findViewById(R.id.SE_check);
				Slop_check = (CheckBox) view.findViewById(R.id.Slop_check);
				RQ_check = (CheckBox) view.findViewById(R.id.RQ_check);
				RQ_Min_check = (CheckBox) view.findViewById(R.id.RQ_Min_check);
				RQ_Max_check = (CheckBox) view.findViewById(R.id.RQ_Max_check);
				MIGHSD_check = (CheckBox) view.findViewById(R.id.MIGHSD_check);
				comments_check = (CheckBox) view.findViewById(R.id.comments_check);
				if (well_check.isChecked()) {

				}
				PopupWindow popupWindow = new PopupWindow(view, 185, LayoutParams.WRAP_CONTENT);
				popupWindow.setBackgroundDrawable(new BitmapDrawable());
				popupWindow.setOutsideTouchable(true);
				popupWindow.setTouchable(true);
				popupWindow.setOutsideTouchable(true);

				// int[] location = new int[2];
				// v.getLocationOnScreen(location);
				// popupWindow.showAtLocation(v, Gravity.NO_GRAVITY,
				// location[0]-185,
				// location[1]);
				popupWindow.showAsDropDown(v);
			}
		});
	}

	class TableAdapter extends BaseAdapter {
		ArrayList<TableFraBean> datas = new ArrayList<TableFraBean>();

		public TableAdapter(ArrayList<TableFraBean> datas) {
			super();
			this.datas = datas;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return datas.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			TableViewHolder holder = null;
			if (convertView == null) {
				holder = new TableViewHolder();
				convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_table_list, null);
				holder.table_list_lin = (LinearLayout) convertView.findViewById(R.id.table_list_lin);

				holder.position_tv = (TextView) convertView.findViewById(R.id.position_tv);
				holder.well_tv = (TextView) convertView.findViewById(R.id.well_tv);
				holder.om_tv = (CheckBox) convertView.findViewById(R.id.om_tv);
				holder.flag_tv = (TextView) convertView.findViewById(R.id.flag_tv);
				holder.sample_tv = (TextView) convertView.findViewById(R.id.sample_tv);
				holder.target_tv = (TextView) convertView.findViewById(R.id.target_tv);
				holder.task_tv = (TextView) convertView.findViewById(R.id.task_tv);
				holder.dyes_tv = (TextView) convertView.findViewById(R.id.dyes_tv);
				holder.ct_tv = (TextView) convertView.findViewById(R.id.ct_tv);
				holder.ct_mean_tv = (TextView) convertView.findViewById(R.id.ct_mean_tv);
				holder.ct_sd_tv = (TextView) convertView.findViewById(R.id.ct_sd_tv);
				holder.quantity_tv = (TextView) convertView.findViewById(R.id.quantity_tv);
				holder.normalized_tv = (TextView) convertView.findViewById(R.id.normalized_tv);
				holder.normalized_se_tv = (TextView) convertView.findViewById(R.id.normalized_se_tv);
				holder.effi_tv = (TextView) convertView.findViewById(R.id.effi_tv);
				holder.slope_tv = (TextView) convertView.findViewById(R.id.slope_tv);
				holder.rq_tv = (TextView) convertView.findViewById(R.id.rq_tv);
				holder.rq_min_tv = (TextView) convertView.findViewById(R.id.rq_min_tv);
				holder.rq_mix_tv = (TextView) convertView.findViewById(R.id.rq_mix_tv);
				holder.hihsd_tv = (TextView) convertView.findViewById(R.id.hihsd_tv);
				holder.comments_tv = (TextView) convertView.findViewById(R.id.comments_tv);

				convertView.setTag(holder);
			} else {
				holder = (TableViewHolder) convertView.getTag();
			}
			if (position % 2 == 0) {
				holder.table_list_lin.setBackgroundColor(getResources().getColor(R.color.darkWhite));
			} else {
				holder.table_list_lin.setBackgroundColor(getResources().getColor(R.color.white));
			}

			holder.position_tv.setText(datas.get(position).getNum());
			holder.well_tv.setText(datas.get(position).getWell());
			holder.flag_tv.setText(datas.get(position).getFlag());
			holder.sample_tv.setText(datas.get(position).getSampleName());
			holder.target_tv.setText(datas.get(position).getTargetName());
			holder.task_tv.setText(datas.get(position).getTask());
			holder.dyes_tv.setText(datas.get(position).getDyes());
			holder.ct_tv.setText(datas.get(position).getCt());
			holder.ct_mean_tv.setText(datas.get(position).getCtMean());
			holder.ct_sd_tv.setText(datas.get(position).getCtSD());
			holder.quantity_tv.setText(datas.get(position).getQuantity());
			holder.normalized_tv.setText(datas.get(position).getNormalizedQuantity());
			holder.normalized_se_tv.setText(datas.get(position).getNormalizedQuantitySE());
			holder.effi_tv.setText(datas.get(position).getEfficiency());
			holder.slope_tv.setText(datas.get(position).getSlop());
			holder.rq_tv.setText(datas.get(position).getrQ());
			holder.rq_min_tv.setText(datas.get(position).getrQMin());
			holder.rq_mix_tv.setText(datas.get(position).getRqMax());
			holder.hihsd_tv.setText(datas.get(position).getMighsd());
			holder.comments_tv.setText(datas.get(position).getComments());

			final int index = position;
			holder.om_tv.setOnCheckedChangeListener(new OnCheckedChangeListener() {

				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

					if (isChecked) {
						mListener.showMessage(index, 0);
						if (index < 16) {
							HashMap<String, Object> hashMap = new HashMap<String, Object>();
							hashMap.put("item_image", "");
							hashMap.put("item_text", "");
							hashMap.put("item_selected", false);

							hashMap.put("item_aisle", 0);
							hashMap.put("item_type", "null");
							dataSourceListBlock1.set(index, hashMap);
						} else {
							HashMap<String, Object> hashMap = new HashMap<String, Object>();
							hashMap.put("item_image", "");
							hashMap.put("item_text", "");
							hashMap.put("item_selected", false);

							hashMap.put("item_aisle", 0);
							hashMap.put("item_type", "null");
							dataSourceListBlock2.set(index - 16, hashMap);
						}
						ArrayList<Integer> integers = new ArrayList<Integer>();
						for (int i = 0; i < tableFraBeans.size(); i++) {
							if (tableFraBeans.get(i).getOmit()) {
								integers.add(i);
							}
						}
						tableFraBeans.clear();
						getTableFragmentBean();

						for (int i = 0; i < integers.size(); i++) {
							tableFraBeans.get(integers.get(i)).setOmit(true);
						}
						tableFraBeans.get(index).setOmit(true);
						notifyDataSetChanged();
					} else {

						mListener.showMessage(index, 1);
						if (index < 16) {
							dataSourceListBlock1.set(index, dataSourceListBlock1Old.get(index));
						} else {
							dataSourceListBlock2.set(index - 16, dataSourceListBlock2Old.get(index - 16));
						}
						ArrayList<Integer> integers = new ArrayList<Integer>();
						for (int i = 0; i < tableFraBeans.size(); i++) {
							if (tableFraBeans.get(i).getOmit()) {
								integers.add(i);
							}
						}
						tableFraBeans.clear();
						getTableFragmentBean();

						for (int i = 0; i < integers.size(); i++) {
							tableFraBeans.get(integers.get(i)).setOmit(true);
						}
						tableFraBeans.get(index).setOmit(false);
						notifyDataSetChanged();

					}

				}

			});
			if (datas.get(position).getOmit()) {
				holder.om_tv.setChecked(true);
			} else {
				holder.om_tv.setChecked(false);
			}

			return convertView;
		}
	}

	class TableViewHolder {
		LinearLayout table_list_lin;
		TextView position_tv;
		TextView well_tv;
		CheckBox om_tv;
		TextView flag_tv;
		TextView sample_tv;
		TextView target_tv;
		TextView task_tv;
		TextView dyes_tv;
		TextView ct_tv;
		TextView ct_mean_tv;
		TextView ct_sd_tv;
		TextView quantity_tv;
		TextView normalized_tv;
		TextView normalized_se_tv;
		TextView effi_tv;
		TextView slope_tv;
		TextView rq_tv;
		TextView rq_min_tv;
		TextView rq_mix_tv;
		TextView hihsd_tv;
		TextView comments_tv;
	}

	public void getStandardRq() {
		// endogenousControl;
		// referenceSample;
		int color = 0;
		// A1的位置集合
		ArrayList<Integer> a1aArrayList = new ArrayList<Integer>(); // 位置
		// A2的位置集合
		HashMap<String, ArrayList<Integer>> a2HashMap = new HashMap<String, ArrayList<Integer>>();// sample
																									// ,位置
		// a2key值集合
		HashSet<String> a2hHashSet = new HashSet<String>();// sample
		// 先检验 基因盘有没有两种target 和两种Sample 没有就rQ系列就为空
		for (int x = 0; x < 16; x++) {

			for (int y = 0; y < activityLayoutTableBeans.size(); y++) {
				if (endogenousControl.equals(activityLayoutTableBeans.get(y).getTarget())) {
					color = activityLayoutTableBeans.get(y).getColor();
				}
			}
			if ((dataSourceListBlock1.get(x).get("item_image").equals(color + ""))) {
				if (referenceSample.equals(dataSourceListBlock1.get(x).get("item_text"))) {

					// a1 ：dataSourceListBlock1.get(x)
					a1aArrayList.add(x);
				} else {
					// a2
					a2hHashSet.add(dataSourceListBlock1.get(x).get("item_text") + "");

					if (a2HashMap.get(dataSourceListBlock1.get(x).get("item_text") + "") == null) {
						ArrayList<Integer> linshiweizhiArrayList = new ArrayList<Integer>();
						linshiweizhiArrayList.add(x);
						if ("sample".equals(dataSourceListBlock1.get(x).get("item_type"))) {
							a2HashMap.put(dataSourceListBlock1.get(x).get("item_text") + "", linshiweizhiArrayList);
						}

					} else {
						ArrayList<Integer> linshiweizhiArrayList = new ArrayList<Integer>();
						linshiweizhiArrayList = a2HashMap.get(dataSourceListBlock1.get(x).get("item_text") + "");
						linshiweizhiArrayList.add(x);
						if ("sample".equals(dataSourceListBlock1.get(x).get("item_type"))) {
							a2HashMap.put(dataSourceListBlock1.get(x).get("item_text") + "", linshiweizhiArrayList);
						}

					}

				}
			} else {
				// rq等为空
			}
			if ((dataSourceListBlock2.get(x).get("item_image").equals(color + ""))) {

				if (referenceSample.equals(dataSourceListBlock2.get(x).get("item_text"))) {

					// a1 ：dataSourceListBlock2.get(x)
					a1aArrayList.add(x + 16);
				} else {
					// a2
					a2hHashSet.add(dataSourceListBlock2.get(x).get("item_text") + "");

					if (a2HashMap.get(dataSourceListBlock2.get(x).get("item_text") + "") == null) {
						ArrayList<Integer> linshiweizhiArrayList = new ArrayList<Integer>();
						linshiweizhiArrayList.add(x + 16);
						if ("sample".equals(dataSourceListBlock2.get(x).get("item_type"))) {
							a2HashMap.put(dataSourceListBlock2.get(x).get("item_text") + "", linshiweizhiArrayList);
						}

					} else {
						ArrayList<Integer> linshiweizhiArrayList = new ArrayList<Integer>();
						linshiweizhiArrayList = a2HashMap.get(dataSourceListBlock2.get(x).get("item_text") + "");
						linshiweizhiArrayList.add(x + 16);
						if ("sample".equals(dataSourceListBlock2.get(x).get("item_type"))) {
							a2HashMap.put(dataSourceListBlock2.get(x).get("item_text") + "", linshiweizhiArrayList);
						}

					}

				}

			} else {
				// rq等为空
			}

		}
		// 找b1b2
		// 找到有referenceSample 和 a2hHashSet拥有相同的target的位置
		ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
		ArrayList<ArrayList<Integer>> resultPostion = new ArrayList<ArrayList<Integer>>();
		for (int i = 0; i < 16; i++) {
			Boolean bBoolean = false;
			// 先找referenceSample 在看有没有 a2hHashSet拥有相同的target的位置
			if ((dataSourceListBlock1.get(i).get("item_text").equals(referenceSample))) {

				// 再次for循环查看有没有这个target有相同的a2hHashSet里的数据
				for (int j = 0; j < 16; j++) {
					for (String ss : a2hHashSet) {
						if (dataSourceListBlock1.get(i).get("item_image")
								.equals(dataSourceListBlock1.get(j).get("item_image"))) {
							// target相同的数据
							if (ss.equals(dataSourceListBlock1.get(j).get("item_text"))) {
								// 和a2hHashSet中有相同的数据
								// 确认b
								// dataSourceListBlock1.get(j).get("item_image")
								// 确认2 ss

								if ("sample".equals(dataSourceListBlock1.get(j).get("item_type"))) {

									bBoolean = true;
									ArrayList<String> strs = new ArrayList<String>();
									// a 1 b 2 ;
									strs.add(endogenousControl);
									strs.add(referenceSample);
									String targetString = "";
									for (int x = 0; x < activityLayoutTableBeans.size(); x++) {
										if (dataSourceListBlock1.get(j).get("item_image")
												.equals(activityLayoutTableBeans.get(x).getColor() + "")) {
											targetString = activityLayoutTableBeans.get(x).getTarget();
										}
									}
									strs.add(targetString);
									strs.add(ss);
									if (!endogenousControl.equals(targetString) && !ss.equals(referenceSample)) {

										result.add(strs);
									} else {

									}
								}
							} else {
								// 无

							}
						} else {
							// 无关数据
						}
						if (dataSourceListBlock1.get(i).get("item_image")
								.equals(dataSourceListBlock2.get(j).get("item_image"))) {
							// target相同的数据
							if (ss.equals(dataSourceListBlock2.get(j).get("item_text"))) {
								// 和a2hHashSet中有相同的数据
								// 确认b
								// dataSourceListBlock2.get(j).get("item_image")
								// 确认2 ss
								if ("sample".equals(dataSourceListBlock2.get(j).get("item_type"))) {
									bBoolean = true;
									ArrayList<String> strs = new ArrayList<String>();
									// a 1 b 2 ;
									strs.add(endogenousControl);
									strs.add(referenceSample);
									String targetString = "";
									for (int x = 0; x < activityLayoutTableBeans.size(); x++) {
										if (dataSourceListBlock2.get(j).get("item_image")
												.equals(activityLayoutTableBeans.get(x).getColor() + "")) {
											targetString = activityLayoutTableBeans.get(x).getTarget();
										}
									}
									strs.add(targetString);
									strs.add(ss);
									result.add(strs);
								}
							} else {
								// 无

							}
						} else {
							// 无关数据
						}

					}
				}
			}
			if ((dataSourceListBlock2.get(i).get("item_text").equals(referenceSample))) {

				// 再次for循环查看有没有这个target有相同的a2hHashSet里的数据
				for (int j = 0; j < 16; j++) {
					for (String ss : a2hHashSet) {
						if (dataSourceListBlock2.get(i).get("item_image")
								.equals(dataSourceListBlock1.get(j).get("item_image"))) {
							// target相同的数据
							if (ss.equals(dataSourceListBlock1.get(j).get("item_text"))) {
								// 和a2hHashSet中有相同的数据
								// 确认b
								// dataSourceListBlock1.get(j).get("item_image")
								// 确认2 ss
								if ("sample".equals(dataSourceListBlock1.get(j).get("item_type"))) {
									bBoolean = true;
									ArrayList<String> strs = new ArrayList<String>();
									// a 1 b 2 ;
									strs.add(endogenousControl);
									strs.add(referenceSample);
									String targetString = "";
									for (int x = 0; x < activityLayoutTableBeans.size(); x++) {
										if (dataSourceListBlock1.get(j).get("item_image")
												.equals(activityLayoutTableBeans.get(x).getColor() + "")) {
											targetString = activityLayoutTableBeans.get(x).getTarget();
										}
									}
									strs.add(targetString);
									strs.add(ss);
									result.add(strs);
								}

							} else {
								// 无

							}
						} else {
							// 无关数据
						}
						if (dataSourceListBlock2.get(i).get("item_image")
								.equals(dataSourceListBlock2.get(j).get("item_image"))) {
							// target相同的数据
							if (ss.equals(dataSourceListBlock2.get(j).get("item_text"))) {
								// 和a2hHashSet中有相同的数据
								// 确认b
								// dataSourceListBlock2.get(j).get("item_image")
								// 确认2 ss
								if ("sample".equals(dataSourceListBlock2.get(j).get("item_type"))) {
									bBoolean = true;
									ArrayList<String> strs = new ArrayList<String>();
									// a 1 b 2 ;
									strs.add(endogenousControl);
									strs.add(referenceSample);
									String targetString = "";
									for (int x = 0; x < activityLayoutTableBeans.size(); x++) {
										if (dataSourceListBlock2.get(j).get("item_image")
												.equals(activityLayoutTableBeans.get(x).getColor() + "")) {
											targetString = activityLayoutTableBeans.get(x).getTarget();
										}
									}
									strs.add(targetString);
									strs.add(ss);
									result.add(strs);
								}
							} else {
								// 无

							}
						} else {
							// 无关数据
						}

					}
				}

			}
		}

		// resut 有所有的数据（4）（有一样的要求取平局值）
		// 求a1 a2 b1 b2 都在哪个位置上然后 求平均值

		String target1, sample1, target2, sample2;
		ArrayList<Integer> a1Positions = new ArrayList<Integer>();
		ArrayList<Integer> a2Positions = new ArrayList<Integer>();
		ArrayList<Integer> b1Positions = new ArrayList<Integer>();
		ArrayList<Integer> b2Positions = new ArrayList<Integer>();

		for (int j = 0; j < result.size(); j++) {
			target1 = result.get(j).get(0);
			sample1 = result.get(j).get(1);
			target2 = result.get(j).get(2);
			sample2 = result.get(j).get(3);

			int color1 = 0, color2 = 0;
			for (int y = 0; y < activityLayoutTableBeans.size(); y++) {
				if (target1.equals(activityLayoutTableBeans.get(y).getTarget())) {
					color1 = activityLayoutTableBeans.get(y).getColor();
					break;
				}
			}
			for (int y = 0; y < activityLayoutTableBeans.size(); y++) {
				if (target2.equals(activityLayoutTableBeans.get(y).getTarget())) {
					color2 = activityLayoutTableBeans.get(y).getColor();
					break;
				}
			}
			for (int x = 0; x < 16; x++) {
				if (dataSourceListBlock1.get(x).get("item_text").equals(sample1)) {

					if (dataSourceListBlock1.get(x).get("item_image").equals(color1 + "")) {
						// a1
						a1Positions.add(x);
					}
					if (dataSourceListBlock1.get(x).get("item_image").equals(color2 + "")) {
						// b1
						b1Positions.add(x);
					}

				}
				if (dataSourceListBlock2.get(x).get("item_text").equals(sample1)) {
					if (dataSourceListBlock2.get(x).get("item_image").equals(color1 + "")) {
						// a1
						a1Positions.add(x + 16);
					}
					if (dataSourceListBlock2.get(x).get("item_image").equals(color2 + "")) {
						// b1
						b1Positions.add(x + 16);
					}

				}

				if (dataSourceListBlock1.get(x).get("item_text").equals(sample2)) {

					if (dataSourceListBlock1.get(x).get("item_image").equals(color1 + "")) {
						// a2
						a2Positions.add(x);
					}
					if (dataSourceListBlock1.get(x).get("item_image").equals(color2 + "")) {
						// b2
						b2Positions.add(x);
					}

				}
				if (dataSourceListBlock2.get(x).get("item_text").equals(sample2)) {
					if (dataSourceListBlock2.get(x).get("item_image").equals(color1 + "")) {
						// a2
						a2Positions.add(x + 16);
					}
					if (dataSourceListBlock2.get(x).get("item_image").equals(color2 + "")) {
						// b2
						b2Positions.add(x + 16);
					}

				}
			}

		}

		// 现在取平均值
		double averageA1, averageA2, averageB1, averageB2;
		int count = 0;
		double sum = 0;
		for (int x = 0; x < a1Positions.size(); x++) {
			count++;

			if ("".equals(tableFraBeans.get(x).getQuantity())) {
				sum = sum + 0;
			} else {
				sum = sum + Double.parseDouble(tableFraBeans.get(x).getQuantity());
			}

		}
		averageA1 = sum / count;
		count = 0;
		sum = 0;
		for (int x = 0; x < a2Positions.size(); x++) {

			count++;

			if ("".equals(tableFraBeans.get(x).getQuantity())) {
				sum = sum + 0;
			} else {
				sum = sum + Double.parseDouble(tableFraBeans.get(x).getQuantity());
			}

		}
		averageA2 = sum / count;
		count = 0;
		sum = 0;
		for (int x = 0; x < b1Positions.size(); x++) {

			count++;

			if ("".equals(tableFraBeans.get(x).getQuantity())) {
				sum = sum + 0;
			} else {
				sum = sum + Double.parseDouble(tableFraBeans.get(x).getQuantity());
			}

		}
		averageB1 = sum / count;
		count = 0;
		sum = 0;
		for (int x = 0; x < b1Positions.size(); x++) {

			count++;

			if ("".equals(tableFraBeans.get(x).getQuantity())) {
				sum = sum + 0;
			} else {
				sum = sum + Double.parseDouble(tableFraBeans.get(x).getQuantity());
			}

		}
		averageB2 = sum / count;
		double rQ = (averageA2 / averageA1) / (averageB2 / averageB1);

		for (int x = 0; x < a1Positions.size(); x++) {
			tableFraBeans.get(a1Positions.get(x)).setrQ(rQ + "");

		}
		for (int x = 0; x < a2Positions.size(); x++) {
			tableFraBeans.get(a2Positions.get(x)).setrQ(rQ + "");

		}
		for (int x = 0; x < b1Positions.size(); x++) {
			tableFraBeans.get(b1Positions.get(x)).setrQ(rQ + "");
		}
		for (int x = 0; x < b2Positions.size(); x++) {
			tableFraBeans.get(b2Positions.get(x)).setrQ(rQ + "");
		}

	}

}
